package cn.zjj.basic.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    private Boolean success=true;
    private String msg="操作成功";
    private Object resultObj=null;
    //成功
    private static JsonResult allJsonResult = new JsonResult();
    //失败
    private static JsonResult noJsonResult = new JsonResult(false,"操作失败");



    public JsonResult(Boolean success, String msg) {
        this.success = success;
        this.msg = msg;

    }

    //失败
    public static JsonResult me(Boolean success, String msg){

        if(success!=null&&msg!=null){
            return noJsonResult;
        }
        return allJsonResult;
    }


    //成功
    public static JsonResult me(){
        return allJsonResult;
    }


    public  JsonResult setResultObj(Object resultObj){
        this.resultObj=resultObj;
        this.success=true;
        return this;
    }


    public  JsonResult runtimeException( String msg){
        this.success=false;
        this.msg=msg;
        return this;
    }
}
